'''
Created on Nov 30, 2011

@author: stelios
'''

from config import cur_static_dir
import os
import time

def clear_temp_folder():
    """
    Clean the temporary folder used for query data, from files that are older than one day
    
    """
    try:    
        path = (cur_static_dir + 'temp/')
        listing = os.listdir(path)
        curtime = time.time()
        for infile in listing:
            temp_file = path + infile
            ftime = os.path.getmtime(temp_file)
            difftime = curtime - ftime
            if difftime > 86400:
                os.unlink(temp_file)
    except Exception as e:
        print e
            